package com.internal.Internalhibernate.server.dao;

// Generated Feb 24, 2012 1:32:12 PM by Hibernate Tools 3.3.0.GA

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.internal.Internalhibernate.client.AdmUniversities;
import com.internal.Internalhibernate.server.SessionFactoryUtil;

/**
 * Home object for domain model class AdmUniversities.
 * 
 * @see com.internal.Internalhibernate.client.AdmUniversities
 * @author Hibernate Tools
 */
public class AdmUniversitiesDAO {
	private static final Log log = LogFactory.getLog(AdmUniversitiesDAO.class);

	private final SessionFactory sessionFactory = SessionFactoryUtil
			.getSessionFactory();

	public void persist(AdmUniversities transientInstance) {
		log.debug("persisting AdmUniversities instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.persist(transientInstance);
			trans.commit();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(AdmUniversities instance) {
		log.debug("attaching dirty AdmUniversities instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.saveOrUpdate(instance);
			trans.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(AdmUniversities instance) {
		log.debug("attaching clean AdmUniversities instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.lock(instance, LockMode.NONE);
			trans.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(AdmUniversities persistentInstance) {
		log.debug("deleting AdmUniversities instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.delete(persistentInstance);
			trans.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("delete failed", re);
			throw re;
		}
	}

	public AdmUniversities merge(AdmUniversities detachedInstance) {
		log.debug("merging AdmUniversities instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			AdmUniversities result = (AdmUniversities) session
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("merge failed", re);
			throw re;
		}
	}

	public AdmUniversities findById(int id) {
		log.debug("getting AdmUniversities instance with id: " + id);
		try {
			Session session = sessionFactory.getCurrentSession();
			session.beginTransaction();
			AdmUniversities instance = (AdmUniversities) session.get(
					"com.internal.Internalhibernate.client.AdmUniversities", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findAll() {
		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		Query q = session.createQuery("from AdmUniversities");
		return q.list();
	}

	public String findUniNameById(int id) {
		List<AdmUniversities> result = null;
		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		Query q = session
				.createQuery("from AdmUniversities where UNI_ID=" + id);
		result = q.list();
		return result.get(0).getUniversity();
	}

}
